﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using WmsApp.WmsService;

namespace WmsApp.Service
{
    public class PayApplyBillWrapService : IWrapService<PayApplyBillWrap>
    {

        #region IWrapService<PayApplyBillWrap> Members

        public void SaveWrap(PayApplyBillWrap wrap)
        {
            var sc = Factory.WmsServiceFactory.GetServiceClient();
            sc.SavePayApplyBillWrap(wrap);
            wrap.FPayApplyBill.WcfEntityState = EntityState.Unchanged;
            if (wrap.FPayApplyBillDtl != null && wrap.FPayApplyBillDtl.Count > 0)
            {
                foreach (var c in wrap.FPayApplyBillDtl)
                {
                    c.WcfEntityState = EntityState.Unchanged;
                }
            }
        }

        public PayApplyBillWrap GetWrap(string wrapMasterID)
        {
            if(String.IsNullOrEmpty(wrapMasterID))
            {
                return null;
            }
            var sc = Factory.WmsServiceFactory.GetServiceClient();
            var wrap = sc.GetPayApplyBillWrap(wrapMasterID);

            if(wrap == null)
            {
                return null;
            }

            wrap.FPayApplyBill.WcfEntityState = EntityState.Unchanged;
            wrap.FPayApplyBill.BindPropertyChanged();
            if (wrap.FPayApplyBillDtl != null && wrap.FPayApplyBillDtl.Count > 0)
            {
                foreach (var c in wrap.FPayApplyBillDtl)
                {
                    c.WcfEntityState = EntityState.Unchanged;
                    c.BindPropertyChanged();
                }
            }
            return wrap;
        }

        #endregion
    }
}
